<?php

/**
 * uniBoard ACP Users List
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http://www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-09-15 17:35:38 +0000 (Wed, 15 Sep 2010) $
 * $Revision: 61 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class action_users{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore		= NULL;
	
	// ------------------------------------------------------------------------

	/**
	 * Initialise Action
	 *
	 * @param object $appCore
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
		// Cache output
		ob_start();
		
		// Count Users to display
		$users_num = $appCore -> db -> count( 'users', 'user_id > \'0\'');
		
		// Make paginator
		$paginator = new class_paginator( $appCore, $appCore -> adminLink( 'act=users&st=%s'), $users_num, 15);
		
		// Draw Paginator
		echo $paginator -> draw();
		
		// Open table block
		echo $appCore -> output -> openTableBlock( $appCore -> lang['acp_found_users_form'] . $appCore -> number( $users_num));
		
		// Draw header
		echo $appCore -> output -> tableHeader( array(
			array(
				'left_float width_icon',
				''
			),
			array(
				'left_float width_medium',
				$appCore -> lang['column_user']
			),
			array(
				'right_float width_medium',
				$appCore -> lang['actions']
			),
			array(
				'right_float width_big',
				$appCore -> lang['column_group']
			)
		));
			
		// Select Users
		$appCore -> db -> query( 'SELECT u.user_id, u.user_login, u.user_name, u.user_email, u.user_avatar_type, u.user_avatar_image, u.user_avatar_width, u.user_avatar_height, g.group_name, g.group_prefix, g.group_suffix
		FROM ' . DB_PREFIX . 'users u
		LEFT JOIN ' . DB_PREFIX . 'user_groups g ON  u.group_id = g.group_id
		WHERE u.user_id > \'0\'
		ORDER BY u.user_name
		LIMIT ' . $paginator -> getPosition() . ',15');
		
		// Parse result
		while ( $user_result = $appCore -> db -> fetch_assoc())
		{				
			// Draw row
			echo $appCore -> output -> tableRow('<table>
	<tr>
		<td class="cell_pad width_icon">
			' . ( $user_result['user_avatar_type'] > 0 ? '<img src="' . class_users::avatarLocation($user_result['user_avatar_type']) . htmlspecialchars($user_result['user_avatar_image']) . '" alt="' . htmlspecialchars( $appCore -> lang['user_avatar']) . '" title="' . htmlspecialchars( $appCore -> lang['user_avatar']) . '" ' . $appCore -> scaleImage( $user_result['user_avatar_width'], $user_result['user_avatar_height'], 32, 32, false) . ' />' : $appCore -> output -> drawImage( 'user_noimage', $appCore -> lang['user_no_avatar'])) . '
		</td>
		<td class="cell_pad left_border">
			<a href="' . $appCore -> niceLink( 'act=user&user=' . $user_result['user_id'], $user_result['user_name']) . '"><b>' . $user_result['user_name'] . '</b></a> <b class="item_append">' . htmlspecialchars( $user_result['user_login']) . '</b>
			<div class="item_description">' . htmlspecialchars( $user_result['user_email']) . '</div>
		</td>
		<td class="cell_pad left_border width_big">
			' . $user_result['group_prefix'] . $appCore -> ifString( htmlspecialchars( $user_result['group_name'])) . $user_result['group_suffix'] . '
		</td>
		<td class="cell_pad left_border width_medium">
			' . $appCore -> output -> toolsPopup( '<div><b>' . $appCore -> lang['acp_user_op_sect_details'] . '</b></div>
<a href="' . $appCore -> adminLink( 'act=edit_user&do=profile&user=' . $user_result['user_id']) . '">' . $appCore -> output -> drawImage( 'action_profile', $appCore -> lang['acp_user_op_profile']) . ' ' . $appCore -> lang['acp_user_op_profile'] . '</a>
<a href="' . $appCore -> adminLink( 'act=edit_user&do=name&user=' . $user_result['user_id']) . '">' . $appCore -> output -> drawImage( 'action_edit', $appCore -> lang['acp_user_op_names']) . ' ' . $appCore -> lang['acp_user_op_names'] . '</a>
<a href="' . $appCore -> adminLink( 'act=edit_user&do=signature&user=' . $user_result['user_id']) . '">' . $appCore -> output -> drawImage( 'action_edit', $appCore -> lang['acp_user_op_signature']) . ' ' . $appCore -> lang['acp_user_op_signature'] . '</a>
<a href="' . $appCore -> adminLink( 'act=edit_user&do=pass&user=' . $user_result['user_id']) . '">' . $appCore -> output -> drawImage( 'action_pass', $appCore -> lang['acp_user_op_pass']) . ' ' . $appCore -> lang['acp_user_op_pass'] . '</a>
<div><b>' . $appCore -> lang['acp_user_op_sect_tools'] . '</b></div>
<a href="' . $appCore -> adminLink( 'act=edit_user&do=prune_keys&user=' . $user_result['user_id']) . '">' . $appCore -> output -> drawImage( 'action_tool', $appCore -> lang['acp_user_op_prune_remember']) . ' ' . $appCore -> lang['acp_user_op_prune_remember'] . '</a>
<a href="' . $appCore -> adminLink( 'act=edit_user&do=prune_posts&user=' . $user_result['user_id']) . '">' . $appCore -> output -> drawImage( 'action_tool', $appCore -> lang['acp_user_op_prune_posts']) . ' ' . $appCore -> lang['acp_user_op_prune_posts'] . '</a>
<div><b>' . $appCore -> lang['acp_user_op_sect_delete'] . '</b></div>
<a href="' . $appCore -> adminLink( 'act=edit_user&do=delete&user=' . $user_result['user_id']) . '">' . $appCore -> output -> drawImage( 'action_delete', $appCore -> lang['acp_user_op_delete_user']) . ' ' . $appCore -> lang['acp_user_op_delete_user'] . '</a>') . '
		</td>
	</tr>
</table>');
		}
		
		// Free result
		$appCore -> db -> freeResult();
		
		// Close table block
		echo $appCore -> output -> closeTableBlock();
		
		// Draw Paginator
		echo $paginator -> draw();
		
		// Draw output
		$appCore -> output -> draw( $appCore -> lang['acp_users_list'], array( $appCore -> adminLink( 'act=users') => $appCore -> lang['acp_users_list']), ob_get_clean());
				
	}

}